import type { Router } from 'vue-router';
import { useAppStore } from '@/store/modules/app';
import { useMultipleTabStore } from '@/store/modules/multipleTab';
// import { useIdentityStore } from '@/store/modules/identity';
import { useAuthStore } from '@/store/modules/auth';
import { PageEnum } from '@/enums/pageEnum';
import { removeTabChangeListener } from '@/logics/mitt/routeChange';

/**
 * 创建状态保护
 * @param router 路由实例
 */
export function createStateGuard(router: Router) {
  router.afterEach((to) => {
    // 只需进入登录页面并清除验证信息（Just enter the login page and clear the authentication information）
    if (to.path === PageEnum.BASE_LOGIN) {
      const tabStore = useMultipleTabStore();
      // const identityStore = useIdentityStore();
      const appStore = useAppStore();
      const authStore = useAuthStore();
      appStore.resetAllState();
      authStore.resetState();
      tabStore.resetState();
      // identityStore.resetState();
      removeTabChangeListener();
    }
  });
}
